<template>
  <div>
    <div class="heard">
      <van-image
        width="60px"
        height="60px"
        fit="cover"
        round
        :src="list.photo"
      />
      <h2>
        {{ list.name }}
        <br />
        <van-tag color="#fff" text-color="skyblue">{{ list.birthday }}</van-tag>
      </h2>
    </div>
    <!-- -------------------------------- -->
    <van-row gutter="20">
      <van-col span="8">
        <van-icon name="newspaper-o" color="pink" />
        <span>
          我的作品
        </span>
      </van-col>
      <van-col span="8">
        <van-icon name="star-o" color="red" />
        <span>我的收藏</span>
      </van-col>
      <van-col span="8">
        <van-icon name="tosend" color="greenyellow" />
        <span>阅读历史</span>
      </van-col>
    </van-row>
    <!-- ----------------------------------------- -->
    <van-cell-group>
      <van-cell
        title="编辑资料"
        icon="edit"
        is-link
        @click="$router.push('/edit')"
      />
      <van-cell
        title="小智同学"
        icon="chat-o"
        is-link
        @click="$router.push('/student')"
      />
      <van-cell title="系统设置" icon="setting-o" is-link />
      <van-cell title="退出登入" icon="warning-o" is-link @click="exitClick" />
    </van-cell-group>
  </div>
</template>

<script>
import { getUserInfo } from './user.js'
import { removeToken } from '@/utils/token.js'
export default {
  name: 'user',
  data () {
    return {
      list: {}
    }
  },
  // 获取axios数据
  created () {
    getUserInfo().then(res => {
      console.log(res)
      this.list = res.data.data
      this.$store.commit('changeRes', res.data.data)
    })
  },
  methods: {
    // 退出登入
    exitClick () {
      this.$dialog
        .confirm({
          title: '标题',
          message: '弹窗内容'
        })
        .then(() => {
          // 清除token
          removeToken()
          // 跳转到登入页
          this.$router.push('/login')
        })
    }
  }
}
</script>

<style scoped lang="less">
.heard {
  height: 100px;
  display: flex;
  align-items: center;
  background: skyblue;
  .van-image {
    padding: 0 10px;
  }
  h2 {
    font-size: 20px;
    font-weight: 400;
    color: #fff;
  }
}
.van-row {
  .van-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 10px 0;
    span {
      margin-top: 5px;
      font-size: 12px;
    }
  }
}
</style>
